import 'package:flutter/widgets.dart';

class PurchaseFlowDisplayTranslation {
  static final delegate = _PurchaseFlowDisplayTranslationDelegate();

  static PurchaseFlowDisplayTranslation of(BuildContext context) {
    return Localizations.of(context, PurchaseFlowDisplayTranslation);
  }

  late String _languageCode;

  Future<void> load(Locale locale) async {
    _languageCode = locale.languageCode;
  }

  String _resolve(Map<String, String> translations) {
    return translations[_languageCode]!;
  }

  String get purchaseRestorationNetworkFailureDialogTitle {
    return _resolve(const {
      'ru': 'Не удалось восстановить покупки. Проверь своё интернет '
          'подключение и попробуй ещё раз.',
      'en': "Couldn't restore purchases. Check you internet connection "
          'and try again.',
    });
  }

  String get purchaseRestorationServerFailureDialogTitle {
    return _resolve(const {
      'ru': 'Что-то пошло не так. Попробуй ещё раз позже.',
      'en': 'Something went wrong. Try again later.',
    });
  }
}

class _PurchaseFlowDisplayTranslationDelegate
    extends LocalizationsDelegate<PurchaseFlowDisplayTranslation> {
  @override
  bool isSupported(Locale locale) => const ['ru', 'en'].contains(locale.languageCode);

  @override
  bool shouldReload(LocalizationsDelegate<PurchaseFlowDisplayTranslation> old) => false;

  @override
  Future<PurchaseFlowDisplayTranslation> load(Locale locale) async {
    final translation = PurchaseFlowDisplayTranslation();
    await translation.load(locale);
    return translation;
  }
}
